#import libraries
import pandas as pd
import numpy as np
import statsmodels.api as sm
from matplotlib import pyplot, pylab
import statsmodels.formula.api as smf
import scipy.stats as stats
import sys

# assign variables
filename = sys.argv[1]
prefix = sys.argv[2]

def main():
	# load data
	data = pd.read_csv(filename, sep=',')
	
	# run the function
	multiple_reg_int = multiple_regression_with_interaction('Multiple_Regression_Interaction.csv')


def multiple_regression_with_interaction(output_file):
    '''calculate the interaction in the multiple regression
    Input: output file name
    Outout: Interaction terms in csv file'''
    
    # load data
    data = pd.read_csv(filename, sep=',')
    
    assert len(data) > 1, 'Dataset should have more than one values'
    
    # running linear regression
    interaction = smf.ols(formula = 'NDVI ~ Temperature * Rain', data=data).fit()
    
    # store the important information (R-square, p-value, and line equation) into a dataframe
    statdf=pd.DataFrame({'formula' : ['y~x', 'y~x', 'y~x'], 'test_stat' : ['rsquared_adj', 'p-val', 'param'], 'value' : [interaction.rsquared_adj, interaction.pvalues[1:], interaction.params] })
   
   	# export the dataframe to a csv file 
    statdf.to_csv(prefix + output_file)


main()